#include "04-encapsulation.h"

/*
 * 线程的封装
 *  创建使用线程时，直接构造对象设置回调函数，对线程原生接口可以进行简单的封装：
 */
 
using namespace std;

void* thread_run(void* args)
{
    std::string name = static_cast<const char *>(args);
    while(true)
    {
        cout << name << endl;
        sleep(1);
    }
}
int main()
{
    std::unique_ptr<Thread> thread1(new Thread(thread_run,(void*)"hellothread",1));
    std::unique_ptr<Thread> thread2(new Thread(thread_run,(void*)"COUTthread",2));
    std::unique_ptr<Thread> thread3(new Thread(thread_run,(void*)"PRINTthread",3));

    //thread1->start();
    //thread2->start();
    //thread3->start();
    thread1->join();
    thread2->join();
    thread3->join();
    return 0;
}

#if 0
PRINTthreadCOUTthread

hellothread
COUTthread
PRINTthread
hellothread
PRINTthread
COUTthread
hellothread
hellothreadCOUTthread

PRINTthread
PRINTthread
hellothread
COUTthread
COUTthreadhellothread

PRINTthread
COUTthread
hellothread

#endif
